﻿Imports System.Data.SqlClient
Public Class DetalleRecepcionDAO
    Public Shared Function insertarDetalleRecepcion(ByVal Ano As String, ByVal ObraSocialXPlanId As Integer, ByVal cantRecetas As Integer, ByVal totalFacturado As Decimal, ByVal aCargoObraSocial As Decimal, ByVal MesId As Integer) As Boolean
        Dim cn As SqlClient.SqlConnection = Nothing
        Try
            cn = Conexion.Conectar
            Dim consulta As New SqlClient.SqlCommand
            With consulta
                .CommandText = "usp_DetalleRecepcionTemporal"
                .CommandType = CommandType.StoredProcedure
                With .Parameters
                    .AddWithValue("@Accion", Constante.INSERTAR).DbType = DbType.Int32
                    .AddWithValue("@Ano", Ano).DbType = DbType.Int32
                    .AddWithValue("@MesId", MesId).DbType = DbType.Int32
                    .AddWithValue("@CantRecetas", cantRecetas).DbType = DbType.Int32
                    .AddWithValue("@totalFacturado", totalFacturado).DbType = DbType.Decimal
                    .AddWithValue("@aCargoObraSocial", aCargoObraSocial).DbType = DbType.Decimal
                    .AddWithValue("@ObraSocialXPlanId", ObraSocialXPlanId).DbType = DbType.Int32
                End With
                .Connection = cn
                .ExecuteNonQuery()
            End With
            Return True
        Catch ex As Exception
            'GUARDAMOS EL ERROR EN LA BD
            ErrorDAO.insertarError(ex)
            Return False
        Finally
            Conexion.Desconectar(cn) 'PASAR POR PARAMETRO LA CONEXION
        End Try
    End Function

    Public Shared Function obtenerDetalleRecepcion() As DataTable
        Dim cn As SqlClient.SqlConnection = Nothing
        Try
            cn = Conexion.Conectar
            Dim ds As New DataSet
            Dim da As New SqlClient.SqlDataAdapter("SELECT * FROM TMP_DetalleRecepcion", cn)
            da.Fill(ds, "DetalleRecepcion")

            Return ds.Tables("DetalleRecepcion")
        Catch ex As Exception
            'GUARDAMOS EL ERROR EN LA BD
            ErrorDAO.insertarError(ex)
            Return Nothing
        Finally
            Conexion.Desconectar(cn) 'PASAR POR PARAMETRO LA CONEXION
        End Try
    End Function

    Public Shared Function limpiarDetalleRecepcion() As Boolean
        Dim cn As SqlClient.SqlConnection = Nothing
        Dim cmd As SqlCommand = Nothing
        Try
            cn = Conexion.Conectar
            cmd = New SqlCommand("Delete from TMP_DetalleRecepcion", cn)
            cmd.ExecuteNonQuery()
            Return True
        Catch ex As Exception
            'GUARDAMOS EL ERROR EN LA BD
            ErrorDAO.insertarError(ex)
            Return False
        Finally
            Conexion.Desconectar(cn) 'PASAR POR PARAMETRO LA CONEXION
        End Try
    End Function
End Class
